package ningbo.serializable;

import java.io.Serializable;

/**
 * @Author 宁铂
 * @Date 2021/7/27 11:05
 * @Version 1.0
 */
/** 如果想让对象完成序列化,就必须要要实现序列化接口 Serializable */
public class Student implements Serializable {
    private static final long serialVersionUID = -1530445615532964098L;
    /** 本类用于封装学生类 */
    //定义属性
    private String name;
    private int age;
    private String addr;
    private char gender;

    //get/set 方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    //构造方法


    public Student() {
        System.out.println("无参构造");
    }

    public Student(String name, int age, String addr, char gender) {
        System.out.println("全参构造");
        this.name = name;
        this.age = age;
        this.addr = addr;
        this.gender = gender;
    }

    //如果不添加重写方法,会默认打印Object里的toString方法,打印的结果会时一串地址值

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", addr='" + addr + '\'' +
                ", gender=" + gender +
                '}';
    }
}
